package com.vf.admin.client.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.vf.admin.client.dao.ExpressionsCommonDao;
import com.vf.admin.client.service.ExpressionsCommonService;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.ExpressionsCommon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Random;

@Service
public class ExpressionsCommonServiceImpl implements ExpressionsCommonService {

    @Autowired
    private ExpressionsCommonDao expressionsCommonDao;

    @Override
    public void saveOrUpdate(ExpressionsCommon param) {
        if (param.getId() != null && param.getId() > 0) {
            expressionsCommonDao.update(param);
        } else {
            expressionsCommonDao.add(param);
        }
    }

    @Override
    public List<ExpressionsCommon> page(SplitPageBean page, Map<String, Object> paraMap) {
        return expressionsCommonDao.page(page, paraMap);
    }

    @Override
    public List<ExpressionsCommon> list(Integer sex) {
        List<ExpressionsCommon> list = expressionsCommonDao.list(sex);
        return list;
    }

    @Override
    public ExpressionsCommon info(Integer id) {
        return expressionsCommonDao.info(id);
    }

    @Override
    public void del(Integer id) {
        expressionsCommonDao.del(id);
    }

    @Override
    public String randomOne(Integer sex) {
        List<ExpressionsCommon> list = expressionsCommonDao.list(sex);
        if (CollectionUtil.isEmpty(list)) {
            return "你好！";
        }
        Random r = new Random();
        return list.get(r.nextInt(list.size())).getContent();
    }

}
